Skip to content

Fix uint64 underflow in slot arithmetic - #92

Open
damilolaedwards wants to merge 1 commit into
ethpandaops:masterfrom
damilolaedwards:fix/slot-arithmetic-underflow
Open

Fix uint64 underflow in slot arithmetic#92
damilolaedwards wants to merge 1 commit into
ethpandaops:masterfrom
damilolaedwards:fix/slot-arithmetic-underflow

Conversation

@damilolaedwards

Copy link
Copy Markdown

Summary

Two spots subtracted slot numbers without checking for underflow, both uint64.

ProposerDelay compared currSlot minus the block's slot against a threshold to skip old blocks. A block one slot ahead of the wallclock, which happens on ordinary clock skew, underflows that subtraction to a huge number and gets silently dropped from the metric instead of recorded.

Empty slot detection computed slot minus one to look up the previous block. At slot 0 that underflows to the max uint64 value and requests a nonsense block.

Test plan

  • Extracted both comparisons into small pure functions (blockTooOldForProposerDelay, previousSlotStateID) and added table-driven tests for each in pkg/beacon/slot_arithmetic_test.go, covering past, current, future and slot-0 cases
  • Confirmed both sets of tests fail against the old unguarded subtraction and pass against the fix
  • go build ./..., go vet ./..., go test -race ./... all green

Two spots subtracted slot numbers without checking for underflow.
ProposerDelay compared currSlot minus the block's slot against a
threshold, so a block one slot ahead of the wallclock (ordinary clock
skew) underflowed to a huge number and got silently dropped instead
of recorded. Empty slot detection computed slot minus one to look up
the previous block, which underflows to the max uint64 at slot 0 and
requests a nonsense block. Both are guarded now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant